<script setup lang="ts">
import { deletevideo, findAll, findAllDZ, update } from "@/api/video";

import { ElContainer, ElHeader, ElMain, FormInstance } from "element-plus";
import { cloneDeep } from "lodash";
import { useUserStore } from "@/store";

const tableData = ref([]);
const loading = ref<boolean>(false);
const tableRef = ref();
const searchFormRef = ref<FormInstance | null>(null);
const dialogVisible = ref<boolean>(false);
const video = ref<Video>();

//双向绑定的对象
const formData = ref(cloneDeep(video));

//添加或编辑框中，用到的对象属性
const DEFAULT_FORM_DATA = {
  id: undefined,
  username: "",
  password: "",
  code: "",
  nick_name: "",
  sex: "",
  birthday: "",
  major_id: "",
  major_name: "",
  head: "",
  department_name: "",
};
//获取 添加/编辑 页面中的表单
const formRef = ref<FormInstance | null>(null);
//重置表单内容
const resetForm = () => {
  formRef.value?.clearValidate();
  formData.value = cloneDeep(DEFAULT_FORM_DATA);
};

//编辑按钮绑定的事件
const handleUpdate = (row: TableData) => {
  dialogVisible.value = true;
  formData.value = cloneDeep(row);
};

const getTableData = () => {
  loading.value = true;
  const userStore = useUserStore();
  const userid = userStore.user.userId;
  findAllDZ(userid)
    .then((res) => {
      tableData.value = res;
    })
    .finally(() => {
      loading.value = false;
    });
};

//删除按钮绑定的事件
const handleDelete = (tableData: any) => {
  ElMessageBox.confirm(`正在删除视频：${tableData.title}，确认删除？`, "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  }).then(() => {
    console.log("aaaa");
    deletevideo(tableData.vid).then(() => {
      ElMessage.success("删除成功");
      window.location.reload();
    });
  });
};

onMounted(() => {
  console.log("asdasdasdas");
  getTableData();
});
</script>

<template>
  <div class="h-full2">
    <h1>我的点赞</h1>
    <div class="my-Video">
      <el-table :data="tableData" ref="tableRef">
        <el-table-column prop="videoUrl" label="视频封面" align="center">
          <template #default="scope">
            <el-avatar
              :src="`http://localhost:8080/api/images/${scope.row.head}`"
            />
          </template>
        </el-table-column>
        <el-table-column prop="title" label="视频标题" align="center" />
        <el-table-column prop="duration" label="视频时长" align="center" />
        <el-table-column prop="plays" label="播放量" align="center" />
        <el-table-column prop="comments" label="评论数" align="center" />
        <el-table-column fixed="right" label="操作" width="150" align="center">
          <template #default="scope">
            <el-button
              type="danger"
              text
              bg
              size="small"
              @click="handleDelete(scope.row)"
            >
              取消点赞
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<style scoped lang="scss">
.common-layout {
  height: 200px;
  width: 100%;
}
.h-full1 {
  height: 200px;
  width: 100%;
  background-color: #f1f2f6;
}
.h-full2 {
  height: 200px;
  width: 100%;
  background-color: #c8c9e6;
}
.h-full3 {
  height: 200px;
  width: 100%;
  background-color: #3f405c;
}
.h-full4 {
  height: 200px;
  width: 100%;
  background-color: #5156c3;
}
</style>
